/*
 * SplashScreen.java
 * 
 * last update: 14.01.2010 by Stefan Saru
 * 
 * author:	Felix(felix@ulise.cs.pub.ro)
 * 
 * Obs: N/A
 */

package ide;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;



/** Splash Screen class
 * -it displays a nice splash screen (what else ?)
 * -inspired from SplashScreen example written by 
 *   Kong Eu Tak for Swing Connection Article
 *       Email: konget@cheerful.com
 *       Homepage: http://www.singnet.com.sg/~kongeuta/
 *
 * @author Lucian Felix Ghita
 * 2:56 AM 3/27/99
 * @ver 1.0 
 */

@SuppressWarnings("serial")
public class SplashScreen extends Window{

	JLabel StatusBar;
	JProgressBar progressBar;
	static int progress = 0;

	public SplashScreen(ImageIcon image){
		super(new Frame());

		JPanel panel=new JPanel(new BorderLayout());

		progressBar = new JProgressBar();
		progressBar.setBorderPainted(false);
		progressBar.setForeground(Color.black);
		progressBar.setBackground(Color.white);



		panel.setLayout(new BorderLayout());
		panel.add(new JLabel(image),BorderLayout.CENTER);
		panel.add(progressBar, BorderLayout.SOUTH);
		progressBar.setStringPainted(true);
		progressBar.setMaximum(46);
		panel.setBorder(new EmptyBorder(0, 0, 0, 0));

		add(panel);   
		pack();

		// centers the whole stuff.
		Dimension WindowSize=getSize(),ScreenSize=Toolkit.getDefaultToolkit().getScreenSize();
		setBounds((ScreenSize.width-WindowSize.width)/2,(ScreenSize.height-WindowSize.height)/2,WindowSize.width,WindowSize.height);
		setVisible(true); 
	}



	public void showStatus(String CurrentStatus){
		try{
			SwingUtilities.invokeAndWait(new UpdateStatus(CurrentStatus));
		}catch(Exception e){e.printStackTrace();}

	}



	public void close(){

		try{
			SwingUtilities.invokeLater(new CloseSplashScreen());
		}catch(Exception e){e.printStackTrace();}

	}



	class UpdateStatus implements Runnable{
		String newStatus;

		public UpdateStatus(String status){
			newStatus=status;
			progress ++;
		}

		public void run(){
			progressBar.setValue(progress);
			progressBar.setString("" + (progress * 100) / progressBar.getMaximum()+ "% " + newStatus);
		}
	}



	class CloseSplashScreen implements Runnable{

		public void run(){
			setVisible(false);
			dispose();
		}
	}
}

